﻿Imports System.Text
Imports AccApp.Models

Public Class clsZModuleScript
    Inherits ADODBU.Recordset

    Private mFieldList As New ArrayList
    Private mStrFieldList As String
    Private mStrSql As String
    Public Sub New()
        mFieldList.Add("ZModuleScript.Mod_Id")
        mFieldList.Add("ZModuleScript.Urut")
        mFieldList.Add("ZModuleScript.Script")
        mStrSql = "Select Mod_Id,Urut,Script from ZModuleScript  "
    End Sub

    Public Overloads Sub Open(ByVal cCriteria As String)
        Dim cSql As String
        cSql = mStrSql & cCriteria
        MyBase.AddPK("Mod_Id")
        MyBase.AddPK("Urut")
        MyBase.IsCanUpdate = True
        Try
            MyBase.Open(cSql, "ZModuleScript", Me.DbConn)
        Catch e As Exception
            Me.ErrMessage = e.Message
        End Try
    End Sub


    Public Function GetRowList(ByVal dbConn As ADODBU.dbConn, ByVal cCriteria As String) As ADODBU.RowClassList(Of clsZModuleScriptRow)
        Dim cmd As System.Data.IDbCommand = dbConn.DBAFactory.GetCommand
        cmd.CommandText = Me.mStrSql & cCriteria
        cmd.CommandType = CommandType.Text
        cmd.Connection = dbConn.Connection
        Return GetDataFromReader(cmd.ExecuteReader)
    End Function

    Public Function GetRowList() As ADODBU.RowClassList(Of clsZModuleScriptRow)
        Return Me.GetDataFromReader(Me.DataTable.CreateDataReader)
    End Function
    Private Function GetDataFromReader(ByVal rdr As IDataReader) As ADODBU.RowClassList(Of clsZModuleScriptRow)
        Dim colData As New ADODBU.RowClassList(Of clsZModuleScriptRow)
        Dim xData As clsZModuleScriptRow
        Dim buffer() As Byte
        Dim len As Long
        Dim mStr As New System.IO.MemoryStream

        Do While rdr.Read
            xData = New clsZModuleScriptRow()
            If Not rdr.IsDBNull(0) Then
                xData.Mod_Id = rdr.GetString(0)
            End If
            If Not rdr.IsDBNull(1) Then
                xData.Urut = rdr.GetInt32(1)
            End If
            If Not rdr.IsDBNull(2) Then
                xData.Script = rdr.GetString(2)
            End If
            colData.Add(xData)
        Loop
        rdr.Close()
        rdr.Dispose()
        Return colData
    End Function

    Public Function GetClassRow() As clsZModuleScriptRow
        Dim crData As New clsZModuleScriptRow
        crData = GetClassRow(Me.GetCurrentDataRow)
        Return crData
    End Function


    Public Function GetClassRow(ByVal recdata As ADODBU.Recordset) As clsZModuleScriptRow
        Dim crData As clsZModuleScriptRow
        crData = New clsZModuleScriptRow(recdata.GetCurrentDataRow)
        Return crData
    End Function


    Public Function GetClassRow(ByVal recdata As DataRow) As clsZModuleScriptRow
        Return New clsZModuleScriptRow(recdata)
    End Function


    Public Function SaveClassRow(ByVal crData As clsZModuleScriptRow, ByVal lAddnew As Boolean, Optional ByVal lTransaction As Boolean = False) As Boolean
        Dim lSavedata As Boolean
        If lAddnew Then
            MyBase.AddNew()
        End If
        crData.DataSource = Me
        crData.SaveToDataSource()
        lSavedata = True
        Try
            MyBase.Update(lTransaction)
            If MyBase.ErrMessage.Length <> 0 Then
                lSavedata = False
            End If
        Catch e As Exception
            lSavedata = False
        End Try
        Return lSavedata
    End Function


End Class
